package com.single;

/**
 * @author cyf
 * @description 单例模式
 * @create 2018-09-20 17:54
 **/
public class SingleTon2 {


    /**
     *  懒汉模式 ：线程安全，加锁; 不足之处：多个线程情况下，阻塞，效率低
     */
    private static SingleTon2 instance;

    private SingleTon2() {
    }

    public synchronized static SingleTon2 getInstance() {
        if(null == instance){
            instance = new SingleTon2();
        }
        return instance;
    }

    public static void main(String[] args) {
        SingleTon2 instance = SingleTon2.getInstance();
        SingleTon2 instance1 = SingleTon2.getInstance();
        System.out.println(instance == instance1);
    }

}
